/**
 * FileFind - ftp/shares indexing and search php engine
 * Module: agent-java
 * Description: Agent written in java language
 * Copyright (c) 2003-2010 Rage Steel, www.gt2.ru
 */
package ru.ffind.agent.dao;

import java.util.Collections;
import java.util.Map;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import ru.ffind.agent.db.DbFilename;

/**
 * Implementation of deleting files in batch.
 *
 * @author Rage Steel
 */
public class DeleteFileBatchImpl extends AbstractBatch
        implements DeleteFileBatch {

    private SimpleJdbcTemplate simpleJdbcTemplate;

    public DeleteFileBatchImpl(SimpleJdbcTemplate simpleJdbcTemplate) {
        this.simpleJdbcTemplate = simpleJdbcTemplate;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void deleteFilename(DbFilename targetFile) {
        fileArgs.add(Collections.singletonMap("file_id",
                (Object)targetFile.getFileId()));
    }

    private static final String SQL = "DELETE FROM `ff_files` " +
            "WHERE :file_id = `file_id`";

    @Override
    protected void doExecute(Map<String, Object>[] batch) {
		simpleJdbcTemplate.batchUpdate(SQL, ArgUtils.toBatchArgs(fileArgs));
    }


}
